$("#usericofw").click(function () {
    $("#userlistStyle1").empty();
    $("#userlistStyle2").empty();
    $("#userlistStyle3").empty();
    $("#userlistStyle1").load("/my_house/list");
}).click();
$("#usericojh_others").click(function () {
    $("#userlistStyle1").empty();
    $("#userlistStyle2").empty();
    $("#userlistStyle3").empty();
    $("#userlistStyle3").load("/my_house/exchang");
});
$("#usericojh_mine").click(function () {
    $("#userlistStyle1").empty();
    $("#userlistStyle2").empty();
    $("#userlistStyle3").empty();
    $("#userlistStyle3").load("/my_house/exchang/mine");
});
$("#usericozr").click(function () {
    $("#userlistStyle1").empty();
    $("#userlistStyle2").empty();
    $("#userlistStyle3").empty();
    $("#userlistStyle1").load("/my_house/transfer");
});
$("#usericodz_hirer").click(function () {
    $("#userlistStyle1").empty();
    $("#userlistStyle2").empty();
    $("#userlistStyle3").empty();
    $("#userlistStyle2").load("/my_house/rent/hirer");
});
$("#usericodz_lessee").click(function () {
    $("#userlistStyle1").empty();
    $("#userlistStyle2").empty();
    $("#userlistStyle3").empty();
    $("#userlistStyle2").load("/my_house/rent/lessee");
});
$("#userright").on('click', '.housePopup .housePopupMain .fa', function () {
    $(".housePopup").hide()
    $("body,html").css({overflow: "auto"})
    $(".checkboxTime").html("")
})
var st;
$("#userright").on('click', ".userhoseDuanzhu", function (e) {
    $(".housePopup").show()
    var scrollTop = $(window).scrollTop();
    $("body,html").css({overflow: "hidden"})
    var guid = $(this).attr("data-id");
    $(".housePopup .housePopupMain input[type=hidden]").val($(this).attr("data-id"));
    $.ajax({
        url: "/rent/renttime/" + guid,
        success: function (data) {
            if (data.length >0) {
                $(".checkboxTime").html("");
                for (var i = 0; i < data.length; i++) {
                    if (i == 0) {
                        $(".housePopup .housePopupMain p").text(data[0].houseInfoDTO.name + "  " + data[0].houseWeekDTO.name)
                    }
                    for (var j = 0; j < data[i].reserveTimeDTOs.length; j++) {
                        if (data[i].reserveTimeDTOs[j].status == "ACTIVITY") {
                            $(".checkboxTime").append('<span style="display: block;"><input type="radio" name="weekTimes" value="' + data[i].reserveTimeDTOs[j].houseWeekTimeDTO.guid + '" id=""><label>' + data[i].reserveTimeDTOs[j].houseWeekTimeDTO.start.replace(/-/g, "/") + '-' + data[i].reserveTimeDTOs[j].houseWeekTimeDTO.end.replace(/-/g, "/") + '</label></span>')
                        }
                    }
                }
            }
            else {
                $(".housePopup .housePopupMain p").text("无出租时间或者房屋在转让/交换中");
            }
        }
    })
})

function getWeekTimesForRent(guid) {
    $.ajax({
        url: "/rent/weekTimes/" + guid,
        type: "post",
        success: function (data) {

        }
    });
}

$("#userright").on('click', '.housePopup .housePopupMain a', function () {
    var days = $(".housePopup .housePopupMain input[type=radio][name=weekTimes]:checked").val();
    var price = $(".housePopup .housePopupMain .price").val();
    var description = $(".housePopup .housePopupMain .description").val();
    var myHouseGuid = $(".housePopup .housePopupMain input[type=hidden]").val();
    $.ajax({
        url: "/rent/init",
        type: "post",
        contentType: 'application/json;charset=UTF-8',
        data: JSON.stringify({myHouseGuid: myHouseGuid, days: days, price: price, information: description}),
        success: function (data) {
            if (data.isSuccess) {
                location.href = "/rent/list";
            } else {
                alert("没有可供短租的时段！");
            }
        }
    });
})

$("#userright .introduce").each(function () {
    if ($(this).text().length > 20) {
        $(this).text($(this).text().substring(0, 20) + "...")
    }
})
//userinfo
function getFileUrl(sourceId) {
    var url;
    if (navigator.userAgent.indexOf("MSIE") >= 1) { // IE
        url = document.getElementById(sourceId).value;
    } else if (navigator.userAgent.indexOf("Firefox") > 0) { // Firefox
        url = window.URL.createObjectURL(document.getElementById(sourceId).files.item(0));
    } else if (navigator.userAgent.indexOf("Chrome") > 0) { // Chrome
        url = window.URL.createObjectURL(document.getElementById(sourceId).files.item(0));
    }
    return url;
}

/**
 * 将本地图片 显示到浏览器上
 */
function preImg(sourceId, targetId) {
    var url = getFileUrl(sourceId);
    var imgPre = document.getElementById(targetId);
    if (imgPre) {
        imgPre.src = url;
    }
}